home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libpod / linfo.c.z / linfo.c
C/C++ Source or Header  |  1996-05-06  |  13KB  |  409 lines

  1. /**************************************************************************
  2.  *
  3.  *           Copyright (c)    1992 Silicon Graphics, Inc.
  4.  *            All Rights Reserved
  5.  *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  7.  *
  8.  * The copyright notice above does not evidence any actual of intended
  9.  * publication of such source code, and is an unpublished work by Silicon
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly
  13.  * prohibited.
  14.  *
  15.  * RESTRICTED RIGHTS LEGEND:
  16.  *
  17.  * Use, duplication or disclosure by the Government is subject to
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311
  24.  **************************************************************************
  25.  *
  26.  * File: linfo.c
  27.  *
  28.  * Description: Sample program that demonstrates the use of the local
  29.  *    form of the libpod info read and write functions.
  30.  *
  31.  *    Usage: linfo printer_name [printer_opt_string]
  32.  *
  33.  *    If printer_opt_string is specified, it is expected to be a quoted
  34.  *    string describing any optional equipment the the specified printer
  35.  *    may contain. An empty string indicates no optional equipment.
  36.  *    An attempt is made to write the optional equipment information into
  37.  *    the specified printer's configuration file.
  38.  *
  39.  *    If printer_opt_string is not specified, the current configuration
  40.  *    and status information is displayed.
  41.  *
  42.  *    Note: You must have root or lp permissions to successfully run
  43.  *    this program to write the config file. There is no such
  44.  *    restriction on reading the config or status files.
  45.  *
  46.  **************************************************************************/
  47.  
  48.  
  49. #ident "$Revision: 1.4 $"
  50.  
  51.  
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <stdlib.h>
  55. #include <time.h>
  56. #include <pod.h>
  57.  
  58.  
  59. #define HANDLE_ERROR(pname)    { \
  60.                 PDPerror(pname); \
  61.                 exit(1); \
  62.                 }
  63.  
  64.  
  65. void usage(char*);
  66. void disp_info(PDInfoStruct*, time_t*);
  67. void disp_opstatus(int);
  68. void disp_status(PDStatusStruct*, PDMessageStruct*);
  69. void disp_config(PDInfoStruct*);
  70. void disp_colorspace(int);
  71. void disp_depth(int);
  72. void disp_format(int);
  73. void disp_pagesize(PDSizeTableStruct*);
  74.  
  75.  
  76. int main(int argc, char **argv)
  77. {
  78.     PDInfoStruct *info, pod_info;
  79.     time_t mod_time;
  80.  
  81.     /*
  82.      * Get the printer name from command line
  83.      */
  84.     if (argc < 2) {
  85.     usage(argv[0]);
  86.     exit(1);
  87.     }
  88.  
  89.     /*
  90.      * Handle the printer options change request
  91.      */
  92.     if (argc == 3) {
  93.     /*
  94.      * Read full info and display current optional equipment
  95.      */
  96.     if (PDLocalReadInfo(argv[1], &info, &mod_time) < 0)
  97.         HANDLE_ERROR(argv[0]);
  98.     (void)printf("Original optional equipment: \"%s\"\n",
  99.                         info->printer_options);
  100.  
  101.     /*
  102.      * Copy the info structure and et active_status to NULL
  103.      * thereby indicating that the status file should not be written
  104.      * only the config file.
  105.      */
  106.     pod_info = *info;
  107.     pod_info.active_status = NULL;
  108.  
  109.     /*
  110.      * Copy the new printer options string into the info struct
  111.      */
  112.     (void)strncpy(pod_info.printer_options, argv[2], PD_STR_MAX);
  113.     pod_info.printer_options[PD_STR_MAX-1] = '\0';
  114.  
  115.     /*
  116.      * Now attempt to write new config file and display what
  117.      * was written.
  118.      */
  119.     if (PDLocalWriteInfo(argv[1], &pod_info) < 0)
  120.         HANDLE_ERROR(argv[0]);
  121.     (void)printf("New optional equipment: \"%s\"\n\n",
  122.                         pod_info.printer_options);
  123.     }
  124.  
  125.     /*
  126.      * Read and display info structure
  127.      */
  128.     if (PDLocalReadInfo(argv[1], &info, &mod_time) < 0)
  129.     HANDLE_ERROR(argv[0]);
  130.     disp_info(info, &mod_time);
  131.  
  132.     return 0;
  133. }
  134.  
  135.  
  136. void usage(char *progname)
  137. {
  138.     (void)fprintf(stderr, "Usage: %s printer_name\n", progname);
  139. }
  140.  
  141.  
  142. void disp_info(PDInfoStruct *info, time_t *mod_timep)
  143. {
  144.     (void)printf("Last Information Modification: %s\n", ctime(mod_timep));
  145.     (void)printf("Status Information\n");
  146.     disp_status(info->active_status, info->error_status);
  147.     (void)printf("\nConfiguration Information\n");
  148.     disp_config(info);
  149. }
  150.  
  151.  
  152. void disp_status(PDStatusStruct *status, PDMessageStruct *messages)
  153. {
  154.     register int i;
  155.     char *options;
  156.  
  157.     disp_opstatus(status->operational_status);
  158.     (void)printf("\tMedia type code:            %d\n", status->media_type);
  159.     (void)printf("\tNumber of colors code:      0x%08X\n",
  160.                                                 status->number_of_colors);
  161.     (void)printf("\t\tNumber of colors:   %d\n",
  162.                                 PD_GET_NUMCOLORS(status->number_of_colors));
  163.     disp_colorspace(PD_GET_COLORSPACE_CODE(status->number_of_colors));
  164.     disp_depth(PD_GET_DEPTH_CODE(status->number_of_colors));
  165.     disp_format(PD_GET_FORMAT_CODE(status->number_of_colors));
  166.     (void)printf("\tMedia size code:            0x%08X\n", status->media_size);
  167.     (void)printf("\tMedia size name:            %s\n",
  168.                                 PDGetNameBySizeCode(status->media_size));
  169.     options = status->printer_options;
  170.     (void)printf("\tInstalled options:          %s\n",
  171.             (options && *options != '\0') ? options: "None");
  172.     (void)printf("\tMedia size validation mask: %d\n", status->validation_mask);
  173.     (void)printf("\tNumber of messages:         %d\n", status->error_count);
  174.     for (i = 0; i < status->error_count; i++) {
  175.     (void)printf("\n\t\tMessage %d code: 0x%08X\n", i+1,
  176.                     messages[i].message_code);
  177.     (void)printf("\t\tMessage %d text: %s\n", i+1,
  178.                         messages[i].message_text);
  179.     }
  180. }
  181.  
  182.  
  183. void disp_opstatus(int status)
  184. {
  185.     (void)printf("\tOperational status:         ");
  186.     switch(status) {
  187.     case PD_STATUS_IDLE:
  188.         (void)printf("IDLE");
  189.         break;
  190.     case PD_STATUS_BUSY:
  191.         (void)printf("BUSY");
  192.         break;
  193.     case PD_STATUS_FAULTED:
  194.         (void)printf("FAULTED");
  195.         break;
  196.     case PD_STATUS_UNAVAILABLE:
  197.         (void)printf("UNAVAILABLE");
  198.         break;
  199.     default:
  200.         (void)printf("UNKNOWN");
  201.         break;
  202.     }
  203.     (void)printf("\n");
  204. }
  205.  
  206.  
  207. void disp_config(PDInfoStruct *info)
  208. {
  209.     register int i;
  210.  
  211.     (void)printf("\tPrinter class: %s\n", info->printer_class);
  212.     (void)printf("\tPrinter model: %s\n", info->printer_model);
  213.     (void)printf("\tPrinter options: %s\n", info->printer_options);
  214.     (void)printf("\tLocation code: %s\n", info->location_code);
  215.     (void)printf("\tPhysical location: %s\n", info->physical_location);
  216.     (void)printf("\tTechnology: %s\n", info->technology);
  217.     (void)printf("\n");
  218.  
  219.     (void)printf("\tConfig file pathname: %s\n", info->config_path);
  220.     (void)printf("\tDriver pathname: %s\n", info->driver_path);
  221.     (void)printf("\tPort pathname: %s\n", info->port_path);
  222.     (void)printf("\tStatus file pathname: %s\n", info->active_path);
  223.     (void)printf("\n");
  224.  
  225.     (void)printf("\tError retry wait: %d\n", info->error_retry_wait);
  226.     (void)printf("\tStatus update wait: %d\n", info->status_update_wait);
  227.     (void)printf("\tMedia wait: %d\n", info->media_wait);
  228.     (void)printf("\n");
  229.  
  230.     (void)printf("\tHorizontal resolution: %d\n", info->horizontal_resolution);
  231.     (void)printf("\tVertical resolution: %d\n", info->vertical_resolution);
  232.     (void)printf("\n");
  233.  
  234.     (void)printf("\tCost per page: %f\n", info->cost_per_page);
  235.     (void)printf("\tAve. time per page: %d\n", info->avg_time_per_page);
  236.     (void)printf("\tMax. time per page: %d\n", info->max_time_per_page);
  237.     (void)printf("\n");
  238.  
  239.     (void)printf("\tMin. number of colors: %d\n", info->min_number_of_colors);
  240.     (void)printf("\tMax. number of colors: %d\n", info->max_number_of_colors);
  241.     (void)printf("\n");
  242.  
  243.     (void)printf("\tMin. horizontal area (in.): %f\n",
  244.                         info->min_area_horizontal);
  245.     (void)printf("\tMin. vertical area (in.): %f\n", info->min_area_vertical);
  246.     (void)printf("\tMax. horizontal area (in.): %f\n",
  247.                         info->max_area_horizontal);
  248.     (void)printf("\tMax. vertical area (in.): %f\n", info->max_area_vertical);
  249.     (void)printf("\n");
  250.  
  251.     (void)printf("\tMin. horizontal area (dots): %d\n",
  252.                         info->min_addr_horizontal);
  253.     (void)printf("\tMin. vertical area (dots): %d\n", info->min_addr_vertical);
  254.     (void)printf("\tMax. horizontal area (dots): %d\n",
  255.                         info->max_addr_horizontal);
  256.     (void)printf("\tMax. vertical area (dots): %d\n", info->max_addr_vertical);
  257.     (void)printf("\n");
  258.  
  259.     (void)printf("\tNumber of quality modes: %d\n", info->quality_modes);
  260.     for (i = 0; i < info->quality_modes; i++)
  261.         (void)printf("\t\tQuality mode %d: %s\n", i+1,
  262.                         info->quality_mode_names[i]);
  263.     if (info->quality_modes)
  264.         (void)printf("\tDefault quality mode: %s\n",
  265.             info->quality_mode_names[info->default_quality_mode-1]);
  266.     (void)printf("\n");
  267.  
  268.     (void)printf("\tManual capable: %s\n", (info->manual_capable) ?
  269.                                 "Yes": "No");
  270.     (void)printf("\tBlack substitute: %s\n", (info->black_substitute) ?
  271.                                 "Yes": "No");
  272.     (void)printf("\tMedia standard: %d\n", info->media_standard);
  273.     (void)printf("\n");
  274.  
  275.     (void)printf("\tNumber of fonts: %d\n", info->avail_fonts);
  276.     for (i = 0; i < info->avail_fonts; i++)
  277.         (void)printf("\t\tFont name %d: %s\n", i+1, info->avail_fonts_names[i]);
  278.     (void)printf("\n");
  279.  
  280.     (void)printf("\tNumber of input sources: %d\n", info->input_sources);
  281.     for (i = 0; i < info->input_sources; i++)
  282.         (void)printf("\t\tInput source %d: %s\n", i+1,
  283.                         info->input_sources_names[i]);
  284.     if (info->input_sources)
  285.         (void)printf("\tDefault input source: %s\n",
  286.             info->input_sources_names[info->default_input_source-1]);
  287.     (void)printf("\tInput source gamma: %f\n", info->input_source_gamma);
  288.     (void)printf("\n");
  289.  
  290.     (void)printf("\tNumber of color adj. schemes: %d\n",
  291.                         info->color_adjustment);
  292.     for (i = 0; i < info->color_adjustment; i++)
  293.         (void)printf("\t\tAdj. scheme %d: %s\n", i+1, info->color_adj_names[i]);
  294.     if (info->color_adjustment)
  295.         (void)printf("\tDefault adj. scheme: %s\n",
  296.             info->color_adj_names[info->default_color_adj-1]);
  297.     (void)printf("\n");
  298.  
  299.     (void)printf("\tNumber of media types: %d\n", info->media_types);
  300.     for (i = 0; i < info->media_types; i++)
  301.         (void)printf("\t\tMedia type %d: %s\n", i+1,
  302.                         info->media_types_names[i]);
  303.     if (info->media_types)
  304.         (void)printf("\tDefault media type: %s\n",
  305.             info->media_types_names[info->default_media_type-1]);
  306.     (void)printf("\n");
  307.  
  308.     (void)printf("\tNumber of size table entries: %d\n",
  309.                         info->size_table_entries);
  310.     for (i = 0; i < info->size_table_entries; i++) {
  311.         (void)printf("\t\tEntry %d:\n", i+1);
  312.     disp_pagesize(&info->size_table[i]);
  313.     }
  314.     (void)printf("\n");
  315. }
  316.  
  317.  
  318. void disp_colorspace(int cspace)
  319. {
  320.     (void)printf("\t\tColorspace:         ");
  321.     switch(cspace) {
  322.         case PD_DATA_K:
  323.             (void)printf("k\n");
  324.             break;
  325.         case PD_DATA_CMY:
  326.             (void)printf("cmy\n");
  327.             break;
  328.         case PD_DATA_CMYK:
  329.             (void)printf("cmyk\n");
  330.             break;
  331.         case PD_DATA_W:
  332.             (void)printf("w\n");
  333.             break;
  334.         case PD_DATA_RGB:
  335.             (void)printf("rgb\n");
  336.             break;
  337.         case PD_DATA_YMC:
  338.             (void)printf("ymc\n");
  339.             break;
  340.         case PD_DATA_YMCK:
  341.             (void)printf("ymck\n");
  342.             break;
  343.         case PD_DATA_KCMY:
  344.             (void)printf("kcmy\n");
  345.             break;
  346.         default:
  347.             (void)printf("0x%08X\n", cspace);
  348.             break;
  349.     }
  350. }
  351.  
  352.  
  353. void disp_depth(int depth)
  354. {
  355.     (void)printf("\t\tDepth:              ");
  356.     switch(depth) {
  357.         case PD_DATA_DEPTH1:
  358.             (void)printf("1 bpp\n");
  359.             break;
  360.         case PD_DATA_DEPTH4:
  361.             (void)printf("4 bpp\n");
  362.             break;
  363.         case PD_DATA_DEPTH8:
  364.             (void)printf("8 bpp\n");
  365.             break;
  366.         default:
  367.             (void)printf("0x%08X\n", depth);
  368.             break;
  369.     }
  370. }
  371.  
  372.  
  373. void disp_format(int format)
  374. {
  375.     (void)printf("\t\tFormat:             ");
  376.     switch(format) {
  377.         case PD_DATA_CHUNKY:
  378.             (void)printf("chunky\n");
  379.             break;
  380.         case PD_DATA_BANDED:
  381.             (void)printf("banded\n");
  382.             break;
  383.         case PD_DATA_PLANAR:
  384.             (void)printf("planar\n");
  385.             break;
  386.         default:
  387.             (void)printf("0x%08X\n", format);
  388.             break;
  389.     }
  390. }
  391.  
  392.  
  393. void disp_pagesize(PDSizeTableStruct *size_info)
  394. {
  395.     (void)printf("\t\t\tMedia size: 0x%08X  %s\n", size_info->media_size,
  396.                         PDGetNameBySizeCode(size_info->media_size));
  397.     (void)printf( "\t\t\tOverall dimensions (inches): %.3f (h) by %.3f (v)\n",
  398.                 size_info->width, size_info->length);
  399.     (void)printf("\t\t\tMargins (inches): %.3f (l), %.3f (t)\n",
  400.                 size_info->left_margin, size_info->top_margin);
  401.     (void)printf("\t\t\tImageable dimensions (dots): %d (h) by %d (v)\n",
  402.                 size_info->horizontal_addr, size_info->vertical_addr);
  403.     (void)printf("\t\t\tRaster definition code: 0x%02X\n",
  404.                         size_info->raster_definition);
  405.     (void)printf("\t\t\tValidation mask: 0x%02X\n", size_info->validation_mask);
  406.     (void)printf("\t\t\tVariable page size code: 0x%02X\n",
  407.                         size_info->variable_page_size);
  408. }
  409.